package logic

import (
	"context"
	"strings"

	"mall/service/recommended/rpc/internal/svc"
	"mall/service/recommended/rpc/types/recommended"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetRecommendListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetRecommendListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRecommendListLogic {
	return &GetRecommendListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetRecommendListLogic) GetRecommendList(in *recommended.RecommendListReq) (*recommended.RecommendListResp, error) {
	if in.UserId == nil || len(strings.TrimSpace(*in.UserId)) == 0 {

	}
	var category string
	var pageSize uint64 = 1
	if in.Category != nil && len(strings.TrimSpace(*in.Category)) >= 0 {
		category = *in.Category
	}
	if in.Limit != nil && *in.Limit > 0 {
		pageSize = *in.Limit
	}
	res, err := l.svcCtx.GorseClient.GetRecommend(l.ctx, *in.UserId, category, int(pageSize))
	if err != nil {
		return nil, err
	}
	return &recommended.RecommendListResp{
		ItemId: res,
	}, nil
}
